/**
 * Created by 徐嘉宾 on 2016/8/21.
 */
$(document).ready(function () {
    $('#w0 tr').each(function () {
        var a = $(this).children('th').text();
        if (a == '一级分类') {
            var b = $(this).children('td');
            $.get("./?r=admin/getclass1", {"id": b.text()}, function (data) {
                b.html(data);
            });
        }
        if (a == '二级分类') {
            var c = $(this).children('td');
            $.get("./?r=admin/getclass2", {"id": c.text()}, function (data) {
                c.html(data);
            });
        }
    });
    $.get("./?r=admin/getreadtype1", function (data) {
        var a = data.split("/");
        for (var i = 0; i < a.length - 1; i++) {
            var j = a[i].split(" ");
            var k = "<option value='" + j[0] + "'>" + j[1] + "</option>";
            $('#writequestion-class1_id').append(k);
        }
    });
    $('#writequestion-class1_id').change(function () {
        $("#writequestion-class2_id option:not(:contains(' '))").remove();
        var b = $('#writequestion-class1_id option:selected').val();
        $.get("./?r=admin/getreadtype2", {id: b}, function (data) {
            var a = data.split("/");
            for (var i = 0; i < a.length - 1; i++) {
                var j = a[i].split(" ");
                var k = "<option value='" + j[0] + "'>" + j[1] + "</option>";
                $('#writequestion-class2_id').append(k);
            }
        });
    });
    if(c1!=false&&c2!=false) {
        $.get("./?r=admin/getclass1", {id: c1}, function (data) {
            var e = data;
            $('#writequestion-class1_id').append("<option value='" + c1 + "' selected='selected'>" + e + "</option>");
        });
        $.get("./?r=admin/getclass2", {id: c2}, function (data) {
            var f = data;
            $('#writequestion-class2_id').append("<option value='" + c2 + "' selected='selected'>" + f + "</option>");
        });
    }

    if(c3!='false'){
        $('#url1').show();
        $('#url1').click(function () {
            $('#url1').hide();
            $('#urlll').append("<a id='geturl'>点击获取url</a>");
            $('#geturl').click(function () {
                $.ajax({
                    url: "./?r=ajax/getwriteurl&id="+h,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#writequestion-url').val(data);
                        $('#geturl').hide();
                    }
                });
            });

        });
    }else{
        $('#url').show();
        $('#url').click(function () {
            var k = $('#writequestion-tnum').val();
            var k1 = $('#writequestion-class2_id').val();
            var k2 = c4;
           $('#url').hide();
            var data = 'www.test.com/img';
            $('#writequestion-url').val(data);
        });
    }


    $('#url1').click(function () {
        $('#url1').hide();
        $('#urlll').append("<a id='geturl'>点击获取url</a>");
        $('#geturl').click(function () {
            $.ajax({
                url: "./?r=ajax/getwriteurl&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#writequestion-url').val(data);
                    $('#geturl').hide();
                }
            });
        });

    });

    if (c5 == 'false') {
        $('#writequestion-index_img_url').hide();
        $('#img').show();
        $('#img').click(function () {
            $('#img').hide();
            $imgcon=$('.field-writequestion-index_img_url');
            $showImg=$('#showImg');
            var data = 'www.test.com/img';
            $('#writequestion-index_img_url').val(data);
            $('#writequestion-index_img_url').show();

        });
    } else {
        // $('#writequestion-index_img_url').hide();
        $('#img1').show();
        $('#img1').click(function () {
            $('#img1').hide();
            $('#imggg').append("<a id='getimg'>点击获取链接</a>");
            $('#getimg').click(function () {
                $.ajax({
                    url: "./?r=ajax/getwriteimgurl&id="+h,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#writequestion-index_img_url').val(data);
                        $('#writequestion-index_img_url').show();
                        $('#getimg').hide();
                    }
                });
            });


        });
    }
    $('#img1').click(function () {
        $('#img1').hide();
        $('#imggg').append("<a id='getimg'>点击获取链接</a>");
        $('#getimg').click(function () {
            $.ajax({
                url: "./?r=ajax/getwriteimgurl&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#writequestion-index_img_url').val(data);
                    $('#writequestion-index_img_url').show();
                    $('#getimg').hide();
                }
            });
        });


    });

    if (c8 == 'false'){

    }else {
        $('#writequestion-class_name option').each(function () {
                 var v = $(this).val();

                 if (v==c8){
                     $(this).attr("selected" ,true);
                 }
             });
    }

    $('#writequestion-reading_content').hide();
    var editor = UE.getEditor('editor');
    if (c6!=false){
        UE.getEditor('editor').ready(function () {
            UE.getEditor('editor').setContent(c6);
        });
    }
    $('.btn-success,.btn-primary').click(function () {
        var g = UE.getEditor('editor').getContent();
        $('#writequestion-reading_content').val(g);
    });
    $('#writequestion-hearing_content').hide();
    var editor1 = UE.getEditor('editor1');
    if (c7!=false){
        UE.getEditor('editor1').ready(function () {
            UE.getEditor('editor1').setContent(c7);
        });
    }
    $('.btn-success,.btn-primary').click(function () {
        var g1 = UE.getEditor('editor1').getContent();
        $('#writequestion-hearing_content').val(g1);
    });
});
